package com.gorkr.cronback.pattern.parser;

/**
 * @author gorkr
 * @title: MonthValueParser
 * @projectName cron
 * @description: TODO
 * @date 2021/12/619:02
 */
public class MonthValueParser extends ValueParser{
    // todo: java Calendar 是从0开始的 可能需要修改
    private static final String[] aliases = {"jan","feb", "mar", "apr", "may","jun", "jul", "aug", "sep","oct", "nov", "dec"};

    public MonthValueParser() {
        super(1, 12);
    }

    @Override
    public int parse(String value){
        try {
            return super.parse(value);
        }catch (Exception e){
            return parseAlias(value);
        }

    }

    // todo: 错误处理
    private int parseAlias(String value){
        for (int i=0; i<aliases.length; i++){
            if(aliases[i].equalsIgnoreCase(value)){
                return i+1;
            }
        }
        return -1;  // 错误
    }

}
